/*
 * PropuestaMoranView.java
 */

package propuestamoran;

import org.jdesktop.application.Action;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;
import org.jdesktop.application.TaskMonitor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Timer;
import javax.swing.Icon;
import javax.swing.JDialog;
import javax.swing.JFrame;

/**
 * The application's main frame.
 */
public class PropuestaMoranView extends FrameView {

    public PropuestaMoranView(SingleFrameApplication app) {
        super(app);

        initComponents();
        
        
        // status bar initialization - message timeout, idle icon and busy animation, etc
        ResourceMap resourceMap = getResourceMap();
        int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
        messageTimer = new Timer(messageTimeout, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                statusMessageLabel.setText("");
            }
        });
        messageTimer.setRepeats(false);
        int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
        for (int i = 0; i < busyIcons.length; i++) {
            busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
        }
        busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
                statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
            }
        });
        idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
        statusAnimationLabel.setIcon(idleIcon);
        progressBar.setVisible(false);

        // connecting action tasks to status bar via TaskMonitor
        TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
        taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                String propertyName = evt.getPropertyName();
                if ("started".equals(propertyName)) {
                    if (!busyIconTimer.isRunning()) {
                        statusAnimationLabel.setIcon(busyIcons[0]);
                        busyIconIndex = 0;
                        busyIconTimer.start();
                    }
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(true);
                } else if ("done".equals(propertyName)) {
                    busyIconTimer.stop();
                    statusAnimationLabel.setIcon(idleIcon);
                    progressBar.setVisible(false);
                    progressBar.setValue(0);
                } else if ("message".equals(propertyName)) {
                    String text = (String)(evt.getNewValue());
                    statusMessageLabel.setText((text == null) ? "" : text);
                    messageTimer.restart();
                } else if ("progress".equals(propertyName)) {
                    int value = (Integer)(evt.getNewValue());
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(false);
                    progressBar.setValue(value);
                }
            }
        });
    }

    @Action
    public void showAboutBox() {
        if (aboutBox == null) {
            JFrame mainFrame = PropuestaMoranApp.getApplication().getMainFrame();
            aboutBox = new PropuestaMoranAboutBox(mainFrame);
            aboutBox.setLocationRelativeTo(mainFrame);
        }
        PropuestaMoranApp.getApplication().show(aboutBox);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mainPanel = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        menuBar = new javax.swing.JMenuBar();
        javax.swing.JMenu CatalogoMenu = new javax.swing.JMenu();
        crearCuentaMenuItem = new javax.swing.JMenuItem();
        borrarCuentaMenuItem = new javax.swing.JMenuItem();
        actualizarCuentaMenuItem = new javax.swing.JMenuItem();
        verCatalogoMenuItem = new javax.swing.JMenuItem();
        javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
        libroDiarioMenu = new javax.swing.JMenu();
        ingresarLibroDiarioMenuItem = new javax.swing.JMenuItem();
        modificarLibroDiarioMenuItem = new javax.swing.JMenuItem();
        verLibroDiarioMenuItem = new javax.swing.JMenuItem();
        libroMayorMenu = new javax.swing.JMenu();
        ejecutarMayorizacionMenuItem = new javax.swing.JMenuItem();
        estadosFinancierosMenu = new javax.swing.JMenu();
        estadoResultadosMenuItem = new javax.swing.JMenuItem();
        balanceComprobacionMenuItem = new javax.swing.JMenuItem();
        balanceGeneralMenuItem = new javax.swing.JMenuItem();
        estadoCapitalMenuItem = new javax.swing.JMenuItem();
        javax.swing.JMenu CreadoresMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();
        statusPanel = new javax.swing.JPanel();
        javax.swing.JSeparator statusPanelSeparator = new javax.swing.JSeparator();
        statusMessageLabel = new javax.swing.JLabel();
        statusAnimationLabel = new javax.swing.JLabel();
        progressBar = new javax.swing.JProgressBar();

        mainPanel.setName("mainPanel"); // NOI18N
        mainPanel.setPreferredSize(new java.awt.Dimension(800, 600));
        mainPanel.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(propuestamoran.PropuestaMoranApp.class).getContext().getResourceMap(PropuestaMoranView.class);
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setBorder(javax.swing.BorderFactory.createTitledBorder(new javax.swing.border.LineBorder(resourceMap.getColor("jLabel1.border.border.lineColor"), 1, true), resourceMap.getString("jLabel1.border.title"), javax.swing.border.TitledBorder.LEFT, javax.swing.border.TitledBorder.DEFAULT_POSITION, resourceMap.getFont("jLabel1.border.titleFont"))); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N
        mainPanel.add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(50, 20, 370, 150));

        jLabel2.setBorder(javax.swing.BorderFactory.createTitledBorder(new javax.swing.border.LineBorder(resourceMap.getColor("jLabel2.border.border.lineColor"), 2, true), resourceMap.getString("jLabel2.border.title"), javax.swing.border.TitledBorder.RIGHT, javax.swing.border.TitledBorder.DEFAULT_POSITION, resourceMap.getFont("jLabel2.border.titleFont"), resourceMap.getColor("jLabel2.border.titleColor"))); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N
        mainPanel.add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(390, 130, 400, 190));

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setBorder(javax.swing.BorderFactory.createTitledBorder(new javax.swing.border.LineBorder(resourceMap.getColor("jLabel3.border.border.lineColor"), 3, true), resourceMap.getString("jLabel3.border.title"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, resourceMap.getFont("jLabel3.border.titleFont"), resourceMap.getColor("jLabel3.border.titleColor"))); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N
        mainPanel.add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 290, 401, 170));

        jLabel4.setIcon(resourceMap.getIcon("jLabel4.icon")); // NOI18N
        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N
        mainPanel.add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(270, 320, 530, 140));

        menuBar.setName("menuBar"); // NOI18N

        CatalogoMenu.setText(resourceMap.getString("CatalogoMenu.text")); // NOI18N
        CatalogoMenu.setName("CatalogoMenu"); // NOI18N

        crearCuentaMenuItem.setText(resourceMap.getString("crearCuentaMenuItem.text")); // NOI18N
        crearCuentaMenuItem.setName("crearCuentaMenuItem"); // NOI18N
        crearCuentaMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                crearCuentaMenuItemActionPerformed(evt);
            }
        });
        CatalogoMenu.add(crearCuentaMenuItem);

        borrarCuentaMenuItem.setText(resourceMap.getString("borrarCuentaMenuItem.text")); // NOI18N
        borrarCuentaMenuItem.setName("borrarCuentaMenuItem"); // NOI18N
        CatalogoMenu.add(borrarCuentaMenuItem);

        actualizarCuentaMenuItem.setText(resourceMap.getString("actualizarCuentaMenuItem.text")); // NOI18N
        actualizarCuentaMenuItem.setName("actualizarCuentaMenuItem"); // NOI18N
        CatalogoMenu.add(actualizarCuentaMenuItem);

        verCatalogoMenuItem.setText(resourceMap.getString("verCatalogoMenuItem.text")); // NOI18N
        verCatalogoMenuItem.setName("verCatalogoMenuItem"); // NOI18N
        verCatalogoMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                verCatalogoMenuItemActionPerformed(evt);
            }
        });
        CatalogoMenu.add(verCatalogoMenuItem);

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(propuestamoran.PropuestaMoranApp.class).getContext().getActionMap(PropuestaMoranView.class, this);
        exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
        exitMenuItem.setName("exitMenuItem"); // NOI18N
        CatalogoMenu.add(exitMenuItem);

        menuBar.add(CatalogoMenu);

        libroDiarioMenu.setText(resourceMap.getString("libroDiarioMenu.text")); // NOI18N
        libroDiarioMenu.setName("libroDiarioMenu"); // NOI18N

        ingresarLibroDiarioMenuItem.setText(resourceMap.getString("ingresarLibroDiarioMenuItem.text")); // NOI18N
        ingresarLibroDiarioMenuItem.setName("ingresarLibroDiarioMenuItem"); // NOI18N
        libroDiarioMenu.add(ingresarLibroDiarioMenuItem);

        modificarLibroDiarioMenuItem.setText(resourceMap.getString("modificarLibroDiarioMenuItem.text")); // NOI18N
        modificarLibroDiarioMenuItem.setName("modificarLibroDiarioMenuItem"); // NOI18N
        libroDiarioMenu.add(modificarLibroDiarioMenuItem);

        verLibroDiarioMenuItem.setText(resourceMap.getString("verLibroDiarioMenuItem.text")); // NOI18N
        verLibroDiarioMenuItem.setName("verLibroDiarioMenuItem"); // NOI18N
        libroDiarioMenu.add(verLibroDiarioMenuItem);

        menuBar.add(libroDiarioMenu);

        libroMayorMenu.setText(resourceMap.getString("libroMayorMenu.text")); // NOI18N
        libroMayorMenu.setName("libroMayorMenu"); // NOI18N

        ejecutarMayorizacionMenuItem.setText(resourceMap.getString("ejecutarMayorizacionMenuItem.text")); // NOI18N
        ejecutarMayorizacionMenuItem.setName("ejecutarMayorizacionMenuItem"); // NOI18N
        libroMayorMenu.add(ejecutarMayorizacionMenuItem);

        menuBar.add(libroMayorMenu);

        estadosFinancierosMenu.setText(resourceMap.getString("estadosFinancierosMenu.text")); // NOI18N
        estadosFinancierosMenu.setName("estadosFinancierosMenu"); // NOI18N

        estadoResultadosMenuItem.setText(resourceMap.getString("estadoResultadosMenuItem.text")); // NOI18N
        estadoResultadosMenuItem.setName("estadoResultadosMenuItem"); // NOI18N
        estadosFinancierosMenu.add(estadoResultadosMenuItem);

        balanceComprobacionMenuItem.setText(resourceMap.getString("balanceComprobacionMenuItem.text")); // NOI18N
        balanceComprobacionMenuItem.setName("balanceComprobacionMenuItem"); // NOI18N
        estadosFinancierosMenu.add(balanceComprobacionMenuItem);

        balanceGeneralMenuItem.setText(resourceMap.getString("balanceGeneralMenuItem.text")); // NOI18N
        balanceGeneralMenuItem.setName("balanceGeneralMenuItem"); // NOI18N
        estadosFinancierosMenu.add(balanceGeneralMenuItem);

        estadoCapitalMenuItem.setText(resourceMap.getString("estadoCapitalMenuItem.text")); // NOI18N
        estadoCapitalMenuItem.setName("estadoCapitalMenuItem"); // NOI18N
        estadosFinancierosMenu.add(estadoCapitalMenuItem);

        menuBar.add(estadosFinancierosMenu);

        CreadoresMenu.setText(resourceMap.getString("CreadoresMenu.text")); // NOI18N
        CreadoresMenu.setName("CreadoresMenu"); // NOI18N

        aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
        aboutMenuItem.setText(resourceMap.getString("aboutMenuItem.text")); // NOI18N
        aboutMenuItem.setName("aboutMenuItem"); // NOI18N
        CreadoresMenu.add(aboutMenuItem);

        menuBar.add(CreadoresMenu);

        statusPanel.setName("statusPanel"); // NOI18N

        statusPanelSeparator.setName("statusPanelSeparator"); // NOI18N

        statusMessageLabel.setName("statusMessageLabel"); // NOI18N

        statusAnimationLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        statusAnimationLabel.setName("statusAnimationLabel"); // NOI18N

        progressBar.setName("progressBar"); // NOI18N

        javax.swing.GroupLayout statusPanelLayout = new javax.swing.GroupLayout(statusPanel);
        statusPanel.setLayout(statusPanelLayout);
        statusPanelLayout.setHorizontalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(statusPanelSeparator, javax.swing.GroupLayout.DEFAULT_SIZE, 801, Short.MAX_VALUE)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(statusMessageLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 631, Short.MAX_VALUE)
                .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(statusAnimationLabel)
                .addContainerGap())
        );
        statusPanelLayout.setVerticalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addComponent(statusPanelSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(statusMessageLabel)
                    .addComponent(statusAnimationLabel)
                    .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(3, 3, 3))
        );

        setComponent(mainPanel);
        setMenuBar(menuBar);
        setStatusBar(statusPanel);
    }// </editor-fold>//GEN-END:initComponents

    private void crearCuentaMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_crearCuentaMenuItemActionPerformed
        CrearCuenta ventanaCrearCuenta=new CrearCuenta();
        ventanaCrearCuenta.setVisible(true);
        ventanaCrearCuenta.setSize(500, 300);
        ventanaCrearCuenta.setLocationRelativeTo(null);
        ventanaCrearCuenta.setDefaultCloseOperation(2);
    }//GEN-LAST:event_crearCuentaMenuItemActionPerformed

    private void verCatalogoMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_verCatalogoMenuItemActionPerformed
          VerCatalogo ventanaVerCatalogo=new VerCatalogo();
          ventanaVerCatalogo.setVisible(true);
          //ventanaVerCatalogo.setSize(500, 300);
          ventanaVerCatalogo.setLocationRelativeTo(null);
          ventanaVerCatalogo.setDefaultCloseOperation(2);
    }//GEN-LAST:event_verCatalogoMenuItemActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuItem actualizarCuentaMenuItem;
    private javax.swing.JMenuItem balanceComprobacionMenuItem;
    private javax.swing.JMenuItem balanceGeneralMenuItem;
    private javax.swing.JMenuItem borrarCuentaMenuItem;
    private javax.swing.JMenuItem crearCuentaMenuItem;
    private javax.swing.JMenuItem ejecutarMayorizacionMenuItem;
    private javax.swing.JMenuItem estadoCapitalMenuItem;
    private javax.swing.JMenuItem estadoResultadosMenuItem;
    private javax.swing.JMenu estadosFinancierosMenu;
    private javax.swing.JMenuItem ingresarLibroDiarioMenuItem;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JMenu libroDiarioMenu;
    private javax.swing.JMenu libroMayorMenu;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JMenuItem modificarLibroDiarioMenuItem;
    private javax.swing.JProgressBar progressBar;
    private javax.swing.JLabel statusAnimationLabel;
    private javax.swing.JLabel statusMessageLabel;
    private javax.swing.JPanel statusPanel;
    private javax.swing.JMenuItem verCatalogoMenuItem;
    private javax.swing.JMenuItem verLibroDiarioMenuItem;
    // End of variables declaration//GEN-END:variables

    private final Timer messageTimer;
    private final Timer busyIconTimer;
    private final Icon idleIcon;
    private final Icon[] busyIcons = new Icon[15];
    private int busyIconIndex = 0;

    private JDialog aboutBox;
}
